Generic Red-Black Tree and its C# Implementation
نویسنده
چکیده
The focus of this installment of the Educator's Corner is on tree construction – red-black trees. Some of the material for this column is taken from Chapter 13 of the forthcoming book " Modern Software Development Using C#/.NET " by Richard Wiener. This book will be published by Thomson, Course Technology in the Fall, 2005. A fascinating and important balanced binary search tree is the red-black tree. Rudolf Bayer invented this important tree structure in 1972, about 10 years after the introduction of AVL trees. He is also credited with the invention of the B-tree, a structure used extensively in database systems. Bayer referred to his red-black trees as " symmetric binary B-trees. " Red-black trees, as they are now known, like AVL trees, are " self-balancing ". Whenever a new object is inserted or deleted, the resulting tree continues to satisfy the conditions required to be a red-black tree. The computational complexity for insertion or deletion can be shown to be O(log 2 n), similar to an AVL tree. Red black trees are important in practice. They are used as the basis for Java's implementation of its standard SortedSet collection class. There is no comparable collection in the C# standard collections so a C# implementation of red-black trees might be useful. The rules that define a red-black tree are interesting because they are less constrained than the rather strict rules associated with an AVL tree. Each node is assigned a color of red or black. This can be accomplished using a field of type bool in class Node (true if the node is red and false if it is black). The formal rules that define a red-black binary search tree are the following: 1. Every node is colored either red or black. 2. The root node is always black. 3. Every external node (null child of a leaf node) is black. 4. If a node is red, both of its children are black. 5. Every path from the root to an external node contains the same number of black nodes.
منابع مشابه
Isabelle Collections Framework
This development provides an efficient, extensible, machine checked collections framework for use in Isabelle/HOL. The library adopts the concepts of interface, implementation and generic algorithm from object-oriented programming and implements them in Isabelle/HOL. The framework features the use of data refinement techniques to refine an abstract specification (using high-level concepts like ...
متن کاملIsabelle Collections Framework
This development provides an efficient, extensible, machine checked collections framework for use in Isabelle/HOL. The library adopts the concepts of interface, implementation and generic algorithm from object-oriented programming and implements them in Isabelle/HOL. The framework features the use of data refinement techniques to refine an abstract specification (using high-level concepts like ...
متن کاملLanguage and Analysis Techniques for Efficient Software Model Checking of Data Structure Properties
This paper presents novel language and analysis techniques that significantly speed up software model checking of data structure properties. Consider checking a red-black tree implementation. Traditional software model checkers systematically generate all red-black tree states (within some given bounds) and check every red-black tree operation (such as insert, delete, or lookup) on every red-bl...
متن کاملHPF vs. SAC — A Case Study
This paper compares the functional programming language Sac to Hpf with respect to specificational elegance and runtime performance. A well-known benchmark, red-black SOR, serves as a case study. After presenting the Hpf reference implementation alternative Sac implementations are discussed. Eventually, performance figures show the ability to compile highly generic Sac specifications into machi...
متن کاملLeft-leaning Red-Black Trees
The red-black tree model for implementing balanced search trees, introduced by Guibas and Sedgewick thirty years ago, is now found throughout our computational infrastructure. Red-black trees are described in standard textbooks and are the underlying data structure for symbol-table implementations within C++, Java, Python, BSD Unix, and many other modern systems. However, many of these implemen...
متن کاملذخیره در منابع من
با ذخیره ی این منبع در منابع من، دسترسی به آن را برای استفاده های بعدی آسان تر کنید
عنوان ژورنال:
- Journal of Object Technology
دوره 4 شماره
صفحات -
تاریخ انتشار 2005